﻿
Partial Class KYC_IndividualAccountPopup
    Inherits System.Web.UI.Page
    Dim ds As System.Data.DataSet = New System.Data.DataSet
    Dim CustSeq As Integer = 0

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            LoadKYCAccount()
        End If

    End Sub

    Private Sub LoadKYCAccount()
        Try
            Dim intANSWERTYPE As Integer = 0

            If Request.QueryString("KYC") = 1 Then
                intANSWERTYPE = 1
            ElseIf Request.QueryString("KYC") = 2 Then
                intANSWERTYPE = 3
            ElseIf Request.QueryString("KYC") = 3 Then
                intANSWERTYPE = 5
            ElseIf Request.QueryString("KYC") = 4 Then
                intANSWERTYPE = 0
            End If

            CustSeq = Request.QueryString("CUSTSEQ")

            If ds.Tables.Contains("RKYC") Then
                ds.Tables.Remove("RKYC")
            End If

            Dim SQLString As String

            SQLString = ""
            SQLString += "   SELECT ANSWERTYPE,                     "
            SQLString += "          ACCOUNTNO,                      "
            SQLString += "          APPROVECODE,                    "
            SQLString += "          ACCOUNTNAME,                    "
            SQLString += "          KYCSEQ,                         "
            SQLString += "          WORKERSTATUS,                   "
            SQLString += "          KYCCOMPLETE,                    "
            SQLString += "          APPROVENO,                      "
            SQLString += "          BRANCHCODE,                     "
            SQLString += "          UPDATEBY,                       "
            SQLString += "          F_JOIN_ACCT,                    "
            SQLString += "          decode (ACCT_STATE,             "
            SQLString += "          'S', 'บัญชีเดี่ยว',                 "
            SQLString += "          'บัญชีร่วม') AS ACCT_STATE,        "

            SQLString += "          decode (ACCT_STATE,             "
            SQLString += "          'M', 'Main',                    "
            SQLString += "          'S', 'Single',                  "
            SQLString += "          'J', 'Join') AS OWNER_STATE,    "

            SQLString += "          decode (DEPUPDATE,              "
            SQLString += "          'D', 'เงินฝาก',                   "
            SQLString += "          'L', 'สินเชื่อ',                    "
            SQLString += "          'P', 'ตั๋วสัญญาใช้เงิน') AS DEPUPDATE,"

            SQLString += "          FLAG_SELF_BO,                   "
            SQLString += "          FLAG_OTHP_BO,                   "
            SQLString += "          ACCT_OPN_DATE,                  "
            SQLString += "          ACCT_CLS_DATE,                  "
            SQLString += "          decode (ACCT_CLS_DATE,          "
            SQLString += "          null, 'Active',                 "
            SQLString += "          'Closed') F_ACCOUNT_CLOSE,      "
            '''
            SQLString += "          ACTIVE                          "
            SQLString += "     FROM RKYC                            "
            SQLString += "    WHERE custseq = " & CustSeq & "       "
            SQLString += "      AND trim(ACCOUNTNO) is not null     "
            SQLString += " ORDER BY KYCSEQ                          "


            Dim con = New clsDatabase

            ds = con.QueryDataSet(SQLString, "RKYC")

            grdShowAccount.DataSource = ds.Tables("RKYC")
            grdShowAccount.DataBind()
            Me.lblCount_Show_ACCT.Text = ds.Tables("RKYC").Rows.Count

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('" & ex.Message.Replace("'", "") & "')", True)
        End Try
    End Sub


    Sub AccountGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then

        End If
    End Sub


    Protected Sub grdShowAccount_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdShowAccount.SelectedIndexChanged
        Try
            CustSeq = Request.QueryString("CUSTSEQ")
            loadBo(CInt(CustSeq), grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text)
            loadCo(grdShowAccount.Rows(grdShowAccount.SelectedIndex).Cells(1).Text)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('" & ex.Message.Replace("'", "") & "')", True)
        End Try
    End Sub

    Private Sub loadBo(ByVal lvsCusSeq As Integer, ByVal AccountNo As String)

        Try
            Dim CUSTTYPE As Int32 = Request.QueryString("KYC")

            If ds.Tables.Contains("MCUST_BO_ACCT") Then
                ds.Tables.Remove("MCUST_BO_ACCT")
            End If

            Dim SQLString As String = ""

            SQLString += "Select ACCOUNTNO              "
            SQLString += "       ,CIF_NO                "
            SQLString += "       ,UNIQUEID              "
            SQLString += "       ,PASSPORT_NO           "
            SQLString += "       ,THFIRSTNAME           "
            SQLString += "       ,THMIDNAME             "
            SQLString += "       ,THLASTNAME            "
            SQLString += "       ,ACC_OWN_RELATION      "
            SQLString += "       ,RISK_LEVEL            "
            SQLString += "       ,FILTER_RESULT         "
            SQLString += "       ,SEQ                   "
            SQLString += "  from KYCADMIN.MCUST_BO_ACCT   "
            SQLString += " where (CustSeq = " & lvsCusSeq & " and ACCOUNTNO = " & AccountNo & ")"

            Dim con = New clsDatabase

            ds = con.QueryDataSet(SQLString, "MCUST_BO_ACCT")


            grdBo.DataSource = ds.Tables("MCUST_BO_ACCT")
            grdBo.DataBind()
            ''''Number of Rows '''''''''''''''''''''
            Me.lblCount_grdBo.Text = ds.Tables("MCUST_BO_ACCT").Rows.Count
            ''''''''''''''''''''''''''''''''''''''''
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('" & ex.Message.Replace("'", "") & "')", True)
        End Try
    End Sub

    Sub loadCo(ByVal AccountNo As String)
        Try
            If ds.Tables.Contains("GRD_CO_ACCT") Then
                ds.Tables.Remove("GRD_CO_ACCT")
            End If

            Dim SQLString As String = ""

            SQLString += "Select a.CUSTSEQ"
            SQLString += ",a.THFIRSTNAME || ' ' || a.THLASTNAME As CUSTNAME"
            SQLString += ",b.ACCOUNTNO"
            SQLString += ",b.ACCOUNTNAME"
            SQLString += ",b.KYCDATE"
            SQLString += " from KYCADMIN.MCUSTOMER a"
            SQLString += " left join KYCADMIN.RKYC b On a.CUSTSEQ = b.CUSTSEQ"
            SQLString += " where(b.ACCOUNTNO = " & AccountNo & " and b.ACCT_STATE = 'J')"

            Dim con = New clsDatabase

            ds = con.QueryDataSet(SQLString, "GRD_CO_ACCT")


            grdCo_Account.DataSource = ds.Tables("GRD_CO_ACCT")
            grdCo_Account.DataBind()


            Me.lblCount_grdCo_Account.Text = ds.Tables("GRD_CO_ACCT").Rows.Count
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "clientScript", "alert('" & ex.Message.Replace("'", "") & "')", True)
        End Try

    End Sub

End Class
